package com.jbp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jbp.dao.EquipRoomBagDao;
import com.jbp.model.EquipRoomBag;
import com.jbp.service.EquipRoomBagService;
import com.jbp.utils.StrToMillsUtil;
import com.mysql.cj.util.TimeUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 房间装备背包(EquipRoomBag)表服务实现类
 * @author cc
 * @since 2021-08-11 12:11:46
 */
@Service
public class EquipRoomBagServiceImpl extends ServiceImpl<EquipRoomBagDao, EquipRoomBag> implements EquipRoomBagService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<EquipRoomBag> queryWrapper = new QueryWrapper<>();
        if (params.get("id") != null){
            queryWrapper.like("id",params.get("id"));
        }
        IPage<EquipRoomBag> page = this.page(
                new Query<EquipRoomBag>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<EquipRoomBag> bagList(Integer roomId){
        QueryWrapper<EquipRoomBag> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type", "bg");
        queryWrapper.eq("room_id", roomId);
//        queryWrapper.apply("UNIX_TIMESTAMP(over_time) >= UNIX_TIMESTAMP('" + StrToMillsUtil.dateToStr(new Date()) + "')");
        queryWrapper.orderByDesc("update_time");
        return list(queryWrapper);
    }

    @Override
    public EquipRoomBag getByEquipId(Integer roomId, Integer equipId) {
        QueryWrapper<EquipRoomBag> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type", "bg");
        queryWrapper.eq("room_id", roomId);
        queryWrapper.eq("equip_id", equipId);
//        queryWrapper.apply("UNIX_TIMESTAMP(over_time) >= UNIX_TIMESTAMP('" + StrToMillsUtil.dateToStr(new Date()) + "')");
        return getOne(queryWrapper);
    }
}